home *** CD-ROM | disk | FTP | other *** search
- /*
- File: EnetLib.h
-
- Contains: Ethernet includes
-
- Version: 1.0.0
-
- Copyright: © 1997-1998 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #ifndef __ENETLIB_H__
- #define __ENETLIB_H__
-
- #include "EnetUser.h"
-
- #ifndef __ENETWARTS_H__
- #define __ENETWARTS_H__
-
- /******************************************************************************/
-
- // The default ForROM is OFF.
- #ifndef ForROM
- #define ForROM 0
- #endif
-
- // #if DEBUG => ASSERT=ON
- // #if ASSERT => assert() enabled
-
- //#define DEBUG 1
-
- // The default DEBUG is OFF.
- #ifndef DEBUG
- #define DEBUG 0
- #endif
-
- #if DEBUG
- // If DEBUG is ON, force ASSERT to ON.
- #undef ASSERT
- #define ASSERT 1
- #endif
-
- // The default ASSERT is OFF.
- #ifndef ASSERT
- #define ASSERT 0
- #endif
-
- extern Boolean gEnetLibDebug; // If true, TPrintf() does DPuts()
- extern Boolean gEnetLibError; // If true, EPrintf() does DPuts()
-
- // Determine default values for gEnetLibDebug and gEnetLibError.
- #if DEBUG
- #define kDefaultEnetLibDebug true
- #else
- #define kDefaultEnetLibDebug false
- #endif
- #if ASSERT
- #define kDefaultEnetLibError true
- #else
- #define kDefaultEnetLibError false
- #endif
-
- // Eliminate DPrintf, TPrintf() and EPrintf() code if ForROM and not DEBUG.
- #if DEBUG
- #define DPRINTF 1
- #define TPRINTF 1
- #define EPRINTF 1
- #else
- #if ForROM
- #define DPRINTF 0
- #define TPRINTF 0
- #define EPRINTF 0
- #else
- #define DPRINTF 1
- #define TPRINTF 1
- #define EPRINTF 1
- #endif
- #endif
-
- /******************************************************************************/
-
- // Allocate a static gSourceVersion from kSourceVersion.
- // Modify to indicate DEBUG/ASSERT with compile data and time.
- #ifdef kSourceVersion
- #if DEBUG
- static const char *gSourceVersion = kSourceVersion"D "__DATE__" "__TIME__;
- #else
- #if ASSERT
- static const char *gSourceVersion = kSourceVersion"A "__DATE__" "__TIME__;
- #else
- static const char *gSourceVersion = kSourceVersion" "__DATE__" "__TIME__;
- #endif
- #endif
- #undef kSourceVersion
- #endif
-
- /******************************************************************************/
-
- #if MACOS || WDISK
-
- // MACOS INCLUDES FOR WARTS MODULE
-
- /******************************************************************************/
-
- #pragma options align=power
-
- #include <stdarg.h>
- #include <DriverServices.h>
- #include <PCI.h>
- #include <Interrupts.h>
- #include <Memory.h>
-
- #define strncpy CStrNCopy
-
- typedef UInt32 Timeout;
- typedef UInt32 Count;
-
- /******************************************************************************/
-
- #define kVersionOneDriverDescriptor kInitialDriverDescriptor
-
- #define development developStage
- #define alpha alphaStage
- #define beta betaStage
- #define final finalStage
-
- /******************************************************************************/
-
- // Delay50Nanoseconds() delays for 50 nanoseconds.
- static Nanoseconds _Delay50Nanoseconds = {0, 50};
- #define Delay50Nanoseconds() \
- DelayForHardware(NanosecondsToAbsolute(_Delay50Nanoseconds))
-
- // Delay100Nanoseconds() delays for 100 nanoseconds.
- static Nanoseconds _Delay100Nanoseconds = {0, 100};
- #define Delay100Nanoseconds() \
- DelayForHardware(NanosecondsToAbsolute(_Delay100Nanoseconds))
-
- // Delay150Nanoseconds() delays for 150 nanoseconds.
- static Nanoseconds _Delay150Nanoseconds = {0, 150};
- #define Delay150Nanoseconds() \
- DelayForHardware(NanosecondsToAbsolute(_Delay150Nanoseconds))
-
- // Delay200Nanoseconds() delays for 200 nanoseconds.
- static Nanoseconds _Delay200Nanoseconds = {0, 200};
- #define Delay200Nanoseconds() \
- DelayForHardware(NanosecondsToAbsolute(_Delay200Nanoseconds))
-
- // Delay250Nanoseconds() delays for 250 nanoseconds.
- static Nanoseconds _Delay250Nanoseconds = {0, 250};
- #define Delay250Nanoseconds() \
- DelayForHardware(NanosecondsToAbsolute(_Delay250Nanoseconds))
-
- // Delay5Microseconds() delays for 5 microseconds.
- #define Delay5Microseconds() \
- DelayForHardware(DurationToAbsolute(-5))
-
- // Delay50Microseconds() delays for 50 microseconds.
- #define Delay50Microseconds() \
- DelayForHardware(DurationToAbsolute(-50))
-
- // Delay250Microseconds() delays for 250 microseconds.
- #define Delay250Microseconds() \
- DelayForHardware(DurationToAbsolute(-250))
-
- // Delay10Milliseconds() delays for 10 milliseconds.
- #define Delay10Milliseconds() \
- DelayForHardware(DurationToAbsolute(10))
-
- /******************************************************************************/
-
- #define Runtime AbsoluteTime
-
- // StartRuntime() returns the runtime NOW.
- #define StartRuntime() \
- UpTime()
-
- // RuntimeEnter() at the beginning of a function collects runtime statistics.
- #define RuntimeEnter(statePtr, function) \
- Runtime _runtime_ = StartRuntime(); \
- (statePtr)->runtime.function##_count++
-
- // RuntimeExit() at the end of a function collects runtime statistics.
- #define RuntimeExit(statePtr, function) \
- _runtime_ = SubAbsoluteFromAbsolute(UpTime(), _runtime_); \
- (statePtr)->runtime.function##_total.lo += _runtime_.lo; \
- if (_runtime_.lo > (statePtr)->runtime.function##_max.lo) { \
- (statePtr)->runtime.function##_max.lo = _runtime_.lo; \
- if (!(statePtr)->runtime.function##_min.lo) \
- (statePtr)->runtime.function##_min.lo = _runtime_.lo; \
- } \
- else if (_runtime_.lo < (statePtr)->runtime.function##_min.lo) \
- (statePtr)->runtime.function##_min.lo = _runtime_.lo; \
-
- // RuntimeCount() is how many times the function has been called.
- #define RuntimeCount(statePtr, function) \
- (statePtr)->runtime.function##_count
-
- // RuntimeTotal() is the total runtime for the function.
- #define RuntimeTotal(statePtr, function) \
- (statePtr)->runtime.function##_total
-
- // RuntimeMinimum() is the minimum runtime for the function.
- #define RuntimeMinimum(statePtr, function) \
- (statePtr)->runtime.function##_min
-
- // RuntimeAverage() is the average runtime for the function.
- #define RuntimeAverage(statePtr, function) \
- DurationToAbsolute( \
- AbsoluteToDuration(RuntimeTotal(statePtr, function)) / \
- (SInt32)RuntimeCount(statePtr, function))
-
- // RuntimeMaximum() is the maximum runtime for the function.
- #define RuntimeMaximum(statePtr, function) \
- (statePtr)->runtime.function##_max
-
- /******************************************************************************/
-
- #define kEthernetPROMProperty "local-mac-address"
- #define kNameProperty "name"
-
- // RegistryFreeProperty() deallocates a registry property.
- // Returns NULL.
- // The property must have been allocated by RegisteryFindProperty().
- extern void *RegistryFreeProperty(void *x);
-
- // RegistryFindProperty() finds a property in the name registery.
- // It allocates memory for the propery, see RegistryFreeProperty().
- // Returns NULL if there was an error.
- extern void *
- RegistryFindProperty(RegEntryIDPtr theID,
- char *propName,
- RegPropertyValueSize *propSize);
-
- // RegistryGetSlotName() finds the name and slot in the name registery.
- // Returns a pointer to a static character buffer.
- extern char *RegistryGetSlotName(RegEntryIDPtr theID);
-
- /******************************************************************************/
-
- #endif // MACOS
-
- #if MACH3
-
- // MACH 3.0 INCLUDES FOR WARTS MODULE
-
- /******************************************************************************/
-
- #include <kern/time_out.h>
- #include <device/device_types.h>
- #include <device/ds_routines.h>
- #include <device/errno.h>
- #include <device/io_req.h>
- #include <device/if_hdr.h>
- #include <device/if_ether.h>
- #include <device/net_status.h>
- #include <device/net_io.h>
- #include <chips/busses.h>
-
- /******************************************************************************/
-
- // Delay50Nanoseconds() delays for 50 nanoseconds.
- #define Delay50Nanoseconds() *unimplemented*
-
- // Delay100Nanoseconds() delays for 100 nanoseconds.
- #define Delay100Nanoseconds() *unimplemented*
-
- // Delay150Nanoseconds() delays for 150 nanoseconds.
- #define Delay150Nanoseconds() *unimplemented*
-
- // Delay200Nanoseconds() delays for 200 nanoseconds.
- #define Delay200Nanoseconds() *unimplemented*
-
- // Delay250Nanoseconds() delays for 250 nanoseconds.
- #define Delay250Nanoseconds() *unimplemented*
-
- // Delay5Microseconds() delays for 5 microseconds.
- #define Delay5Microseconds() *unimplemented*
-
- // Delay50Microseconds() delays for 50 microseconds.
- #define Delay50Microseconds() *unimplemented*
-
- // Delay250Microseconds() delays for 250 microseconds.
- #define Delay250Microseconds() *unimplemented*
-
- // Delay10Milliseconds() delays for 10 milliseconds.
- #define Delay10Milliseconds() *unimplemented*
-
- /******************************************************************************/
-
- #define Runtime *unimplemented*
-
- // StartRuntime() returns the runtime NOW.
- #define StartRuntime() *unimplemented*
-
- // RuntimeEnter() at the beginning of a function collects runtime statistics.
- #define RuntimeEnter(statePtr, function) *unimplemented*
-
- // RuntimeExit() at the end of a function collects runtime statistics.
- #define RuntimeExit(statePtr, function) *unimplemented*
-
- // RuntimeCount() is how many times the function has been called.
- #define RuntimeCount(statePtr, function) *unimplemented*
-
- // RuntimeTotal() is the total runtime for the function.
- #define RuntimeTotal(statePtr, function) *unimplemented*
-
- // RuntimeMinimum() is the minimum runtime for the function.
- #define RuntimeMinimum(statePtr, function) *unimplemented*
-
- // RuntimeAverage() is the average runtime for the function.
- #define RuntimeAverage(statePtr, function) *unimplemented*
-
- // RuntimeMaximum() is the maximum runtime for the function.
- #define RuntimeMaximum(statePtr, function) *unimplemented*
-
- /******************************************************************************/
-
- #endif // MACH3
-
- /******************************************************************************/
-
- // DeallocateMemory() deallocates general purpose memory.
- // Returns NULL.
- // The memory will be zeroed if a size > 0 is specified.
- // The memory must have been allocated with AllocateMemory().
- extern void *DeallocateMemory(void *x, Size);
-
- // AllocateMemory() allocates general purpose memory.
- // Returns NULL if there was an error.
- extern void *AllocateMemory(Size, Boolean zero);
-
- /******************************************************************************/
-
- // _Printf() formats an output character stream.
- // Returns the number of characters output.
- // Returns -1 if there was an error.
- extern int _Printf(void *, int (*)(int, void *), const char *, va_list);
-
- /******************************************************************************/
-
- typedef struct BPrintfBuffer BPrintfBuffer;
- typedef BPrintfBuffer * BPrintfBufferPtr;
- struct BPrintfBuffer {
- char * begin; // &buffer[0]
- char * end; // &buffer[size]
- char * next; // &buffer[nextPutc]
- };
- typedef BPrintfBufferPtr BPrintfPtr;
-
- // BPrintfPutc() is the putc routine used by _BPrintf().
- // Returns zero.
- // Returns -1 if there was an error.
- // It does not NULL-terminate the buffer.
- extern int BPrintfPutc(int c, void *output);
-
- // ResetBPrintf() prepares a BPrintfBuffer.
- extern void ResetBPrintf(BPrintfPtr, char *, Size);
-
- // CheckBPrintf() checks for a minimum free space.
- // Returns false if there was an error.
- Boolean CheckBPrintf(BPrintfPtr b, Count minFree);
-
- // _BPrintf() is a varargs version of BPrintf().
- // Returns the number of characters output.
- // Returns -1 if there was an error.
- // It can not step outside of its buffer.
- extern int _BPrintf(BPrintfPtr, const char *, va_list);
-
- // BPrintf() is used like sprintf().
- // Returns the number of characters output.
- // Returns -1 if there was an error.
- // It can not step outside of its buffer, unlike sprintf().
- extern int BPrintf(BPrintfPtr, const char *, ...);
-
- /******************************************************************************/
-
- // _SPrintf() is a varargs version of SPrintf().
- // Returns the number of characters output.
- // Returns -1 if there was an error.
- // It can not step outside of its buffer.
- extern int _SPrintf(char *, Size, const char *, va_list);
-
- // SPrintf() is a safe version of sprintf().
- // Returns the number of characters output.
- // Returns -1 if there was an error.
- // It can not step outside of its buffer, unlike sprintf().
- extern int SPrintf(char *, Size, const char *, ...);
-
- /******************************************************************************/
-
- // DPuts() displays a message then enters the debugger.
- extern void DPuts(const char *);
-
- // DPrintf() formats and displays a message then enters the debugger.
- extern void _DPrintf(const char *, ...);
- #if DPRINTF
- #define DPrintf(args) _DPrintf##args
- #else
- #define DPrintf(args)
- #endif
-
- // _assert() enters the debugger when an assertion fails.
- extern int _assert(const char *, const int, const char *);
-
- #if ASSERT
- // Save some space with assert().
- // Put these two lines at the top of each source file.
- // #define kAssertFile __FILE__
- // static const char *gAssertFile = kAssertFile;
- #ifdef kAssertFile
- #undef assert
- #define assert(x) ((void)((x) ? 0 : _assert(gAssertFile, __LINE__, #x), 1))
- #else
- #undef assert
- #define assert(x) ((void)((x) ? 0 : _assert(__FILE__, __LINE__, #x), 1))
- #endif
- #else
- #undef assert
- #define assert(x)
- #endif
-
- /******************************************************************************/
-
- typedef struct MPrintfBuffer MPrintfBuffer;
- typedef MPrintfBuffer * MPrintfBufferPtr;
- typedef MPrintfBufferPtr MPrintfPtr;
-
- // CloseMPrintf() terminates access to an error buffer.
- // Returns NULL.
- // This invalidates the MPrintfBuffer pointer.
- extern MPrintfPtr CloseMPrintf(MPrintfPtr);
-
- // ResetMPrintf() clears and resets a MPrintfBuffer.
- extern void ResetMPrintf(MPrintfPtr m);
-
- // OpenMPrintf() prepares a MPrintfBuffer of the specified size.
- // Returns NULL if there was an error.
- extern MPrintfPtr OpenMPrintf(Size);
-
- // MPuts() inserts a message into an MPrintfBuffer.
- // Use '\n' between messages lines.
- extern void MPuts(MPrintfPtr, const char *);
-
- // MPrintf() formats and inserts a message into an MPrintfBuffer.
- // Use '\n' between messages lines.
- extern void MPrintf(MPrintfPtr, const char *, ...);
-
- // ReadMPrintfLine() extracts a single line from the MPrintfBuffer.
- extern void ReadMPrintfLine(BPrintfPtr output, MPrintfPtr m, char *line);
-
- // ReadMPrintfBuffer() extracts MPrintfBuffer lines in reverse order.
- // Returns false if there was an error.
- extern Boolean ReadMPrintfBuffer(BPrintfPtr, MPrintfPtr, Count);
-
- /******************************************************************************/
-
- // TPrintf() formats a trace message.
- // The message is inserted into the MPrintf buffer if one is specified.
- // It will DPuts() if DEBUG is defined non-zero.
- extern void _TPrintf(MPrintfPtr m, const char *format, ...);
- #if TPRINTF
- #define TPrintf(args) _TPrintf##args
- #else
- #define TPrintf(args)
- #endif
-
- /******************************************************************************/
-
- // EPrintf() formats an error message.
- // The message is inserted into the MPrintf buffer if one is specified.
- // It will DPuts() if ASSERT is defined non-zero.
- extern void _EPrintf(MPrintfPtr, const char *, ...);
- #if EPRINTF
- #define EPrintf(args) _EPrintf##args
- #else
- #define EPrintf(args)
- #endif
-
- // ECheckUInt8() checks two numbers.
- // Does EPrintf and returns false if they are not the same.
- extern Boolean ECheckUInt8(MPrintfPtr, UInt8, UInt8, const char *, ...);
-
- // ECheckUInt16() checks two numbers.
- // Does EPrintf and returns false if they are not the same.
- extern Boolean ECheckUInt16(MPrintfPtr, UInt16, UInt16, const char *, ...);
-
- // ECheckUInt32() checks two numbers.
- // Does EPrintf and returns false if they are not the same.
- extern Boolean ECheckUInt32(MPrintfPtr, UInt32, UInt32, const char *, ...);
-
- // ECheckSInt32() checks two numbers.
- // Does EPrintf and returns false if they are not the same.
- extern Boolean ECheckSInt32(MPrintfPtr, SInt32, SInt32, const char *, ...);
-
- // ECheckUInt8Range() checks a number against a range.
- // Does EPrintf and returns false if the number is out of range.
- extern Boolean
- ECheckUInt8Range(MPrintfPtr, UInt8, UInt8, UInt8, const char *, ...);
-
- // ECheckUInt16Range() checks a number against a range.
- // Does EPrintf and returns false if the number is out of range.
- extern Boolean
- ECheckUInt16Range(MPrintfPtr, UInt16, UInt16, UInt16, const char *, ...);
-
- // ECheckUInt32Range() checks a number against a range.
- // Does EPrintf and returns false if the number is out of range.
- extern Boolean
- ECheckUInt32Range(MPrintfPtr, UInt32, UInt32, UInt32, const char *, ...);
-
- // ECheckUInt32() checks two pointers.
- // Does EPrintf and returns false if they do not match.
- extern Boolean ECheckPtr(MPrintfPtr, void *, void *, const char *, ...);
-
- // ECheckNullPtr() checks for a null pointer.
- // Does EPrintf and returns false if the pointer is null.
- extern Boolean ECheckNullPtr(MPrintfPtr, void *, const char *, ...);
-
- /******************************************************************************/
-
- // Delay50Nanoseconds() delays for 50 nanoseconds.
- // Error if Delay50Nanoseconds() not defined by OS-specific code.
- #ifndef Delay50Nanoseconds
- #define Delay50Nanoseconds() *unimplemented*
- #endif
-
- // Delay100Nanoseconds() delays for 100 nanoseconds.
- // Error if Delay100Nanoseconds() not defined by OS-specific code.
- #ifndef Delay100Nanoseconds
- #define Delay100Nanoseconds() *unimplemented*
- #endif
-
- // Delay150Nanoseconds() delays for 150 nanoseconds.
- // Error if Delay150Nanoseconds() not defined by OS-specific code.
- #ifndef Delay150Nanoseconds
- #define Delay150Nanoseconds() *unimplemented*
- #endif
-
- // Delay200Nanoseconds() delays for 200 nanoseconds.
- // Error if Delay200Nanoseconds() not defined by OS-specific code.
- #ifndef Delay200Nanoseconds
- #define Delay200Nanoseconds() *unimplemented*
- #endif
-
- // Delay250Nanoseconds() delays for 250 nanoseconds.
- // Error if Delay250Nanoseconds() not defined by OS-specific code.
- #ifndef Delay250Nanoseconds
- #define Delay250Nanoseconds() *unimplemented*
- #endif
-
- // Delay5Microseconds() delays for 5 microseconds.
- // Error if Delay5Microseconds() not defined by OS-specific code.
- #ifndef Delay5Microseconds
- #define Delay5Microseconds() *unimplemented*
- #endif
-
- // Delay50Microseconds() delays for 50 microseconds.
- // Error if Delay50Microseconds() not defined by OS-specific code.
- #ifndef Delay50Microseconds
- #define Delay50Microseconds() *unimplemented*
- #endif
-
- // Delay250Microseconds() delays for 250 microseconds.
- // Error if Delay250Microseconds() not defined by OS-specific code.
- #ifndef Delay250Microseconds
- #define Delay250Microseconds() *unimplemented*
- #endif
-
- // Delay10Milliseconds() delays for 10 milliseconds.
- // Error if Delay10Milliseconds() not defined by OS-specific code.
- #ifndef Delay10Milliseconds
- #define Delay10Milliseconds() *unimplemented*
- #endif
-
- /******************************************************************************/
-
- // Error if Runtime not defined by OS-specific code.
- #ifndef Runtime
- #define Runtime *unimplemented*
- #endif
-
- // StartRuntime() returns the runtime NOW.
- // Error if StartRuntime() not defined by OS-specific code.
- #ifndef StartRuntime
- #define StartRuntime() *unimplemented*
- #endif
-
- // Delay for a minimum number of microseconds.
- // Returns false if no delay.
- extern Boolean RuntimeDelay(Runtime *lastTime, UInt32 microseconds);
-
- // RuntimeDelta() returns a runtime delta in microseconds.
- extern UInt32 RuntimeDelta(Runtime before, Runtime after);
-
- // ElapsedRuntime() returns the number of microseconds since the startTime.
- extern UInt32 ElapsedRuntime(Runtime);
-
- // RuntimeToString() formats an Runtime value into a string buffer.
- // Returns a pointer to a single static string buffer.
- extern char *RuntimeToString(Runtime);
-
- // RuntimeEnter() at the beginning of a function collects runtime statistics.
- // Error if RuntimeEnter() not defined by OS-specific code.
- #ifndef RuntimeEnter
- #define RuntimeEnter(statePtr, function) *unimplemented*
- #endif
-
- // RuntimeExit() at the end of a function collects runtime statistics.
- // Error if RuntimeExit() not defined by OS-specific code.
- #ifndef RuntimeExit
- #define RuntimeExit(statePtr, function) *unimplemented*
- #endif
-
- // RuntimeCount() is how many times the function has been called.
- // Error if RuntimeCount() not defined by OS-specific code.
- #ifndef RuntimeCount
- #define RuntimeCount(statePtr, function) *unimplemented*
- #endif
-
- // RuntimeTotal() is the total runtime for the function.
- // Error if RuntimeTotal() not defined by OS-specific code.
- #ifndef RuntimeTotal
- #define RuntimeTotal(statePtr, function) *unimplemented*
- #endif
-
- // RuntimeMinimum() is the minimum runtime for the function.
- // Error if RuntimeMinimum() not defined by OS-specific code.
- #ifndef RuntimeMinimum
- #define RuntimeMinimum(statePtr, function) *unimplemented*
- #endif
-
- // RuntimeAverage() is the average runtime for the function.
- // Error if RuntimeAverage() not defined by OS-specific code.
- #ifndef RuntimeAverage
- #define RuntimeAverage(statePtr, function) *unimplemented*
- #endif
-
- // RuntimeMaximum() is the maximum runtime for the function.
- // Error if RuntimeMaximum() not defined by OS-specific code.
- #ifndef RuntimeMaximum
- #define RuntimeMaximum(statePtr, function) *unimplemented*
- #endif
-
- // ClearRuntime() zeros the runtime counters.
- #define ClearRuntime(statePtr) \
- BlockZero(&(statePtr)->runtime, sizeof((statePtr)->runtime))
-
- // RuntimeFunction() defines runtime fields for a function.
- #define RuntimeFunction(function) \
- Count function##_count; \
- Runtime function##_total; \
- Runtime function##_min; \
- Runtime function##_max \
-
- // RuntimeReport() composes a runtime report for a function.
- #define RuntimeReport(b, statePtr, function) \
- BPrintf(b, \
- #function" %lu %T, %T, %T, %T\n", \
- RuntimeCount(statePtr, function), \
- RuntimeTotal(statePtr, function), \
- RuntimeMinimum(statePtr, function), \
- RuntimeAverage(statePtr, function), \
- RuntimeMaximum(statePtr, function))
-
- #if !RUNTIME
-
- // RuntimeEnter() does nothing if RUNTIME is not defined non-zero.
- #undef RuntimeEnter
- #define RuntimeEnter(statePtr, function)
-
- // RuntimeExit() does nothing if RUNTIME is not defined non-zero.
- #undef RuntimeExit
- #define RuntimeExit(statePtr, function)
-
- #endif
-
- /******************************************************************************/
-
- // DeallocateMemoryForIO() deallocates I/O memory.
- // Returns NULL.
- // The memory must have been allocated with AllocateMemoryForIO().
- extern void *DeallocateMemoryForIO(void *MemoryForIO, Boolean zero);
-
- // AllocateMemoryForIO() allocates I/O memory.
- // Returns NULL if there was an error.
- extern void *AllocateMemoryForIO(Size size, Boolean zero);
-
- // LogicalToPhysical() translates a logical address to a physical address.
- extern UInt32 LogicalToPhysical(void *MemoryForIO, void *logical);
-
- // LogicalToPhysicalES() translates a logical address to a physical address.
- // The physical address is endian swapped.
- extern UInt32 LogicalToPhysicalES(void *MemoryForIO, void *logical);
-
- /******************************************************************************/
-
- typedef struct Interrupt Interrupt;
- typedef Interrupt *InterruptPtr;
-
- // CloseInterrupt() removes an interrupt service routine.
- // The interrupt state pointer is invalidated.
- // Returns NULL.
- extern InterruptPtr CloseInterrupt(InterruptPtr);
-
- // OpenInterrupt() installs an interrupt service routine.
- // Returns a pointer to the interrupt state.
- // Returns NULL if there was an error.
- extern InterruptPtr
- OpenInterrupt(RegEntryIDPtr,
- int ISTPropertyIndex,
- InterruptHandler,
- void *);
-
- // EnableInterrupt() enables the specified interrupt.
- extern void EnableInterrupt(InterruptPtr);
-
- // DisableInterrupt() disables the specified interrupt.
- extern void DisableInterrupt(InterruptPtr);
-
- /******************************************************************************/
-
- // PCIWriteUInt16() writes a UInt16 to the PCI configuration.
- // Returns false if there was an error.
- extern Boolean PCIWriteUInt16(void *cookie, UInt32 address, UInt16 value);
-
- // PCIReadUInt16() reads a UInt16 from the PCI configuration.
- // Returns false if there was an error.
- extern Boolean PCIReadUInt16(void *cookie, UInt32 address, UInt16 *value);
-
- // PCIWriteUInt32() writes a UInt32 to the PCI configuration.
- // Returns false if there was an error.
- extern Boolean PCIWriteUInt32(void *cookie, UInt32 address, UInt32 value);
-
- // PCIReadUInt32() reads a UInt32 from the PCI configuration.
- // Returns false if there was an error.
- extern Boolean PCIReadUInt32(void *cookie, UInt32 address, UInt32 *value);
-
- /******************************************************************************/
-
- // Reverse8Bit() reverses the bits in an 8-bit number.
- extern UInt8 Reverse8Bit(UInt8);
-
- // Reverse32Bit() reverses the bits in an 32-bit number.
- extern UInt32 Reverse32Bit(UInt32);
-
- // CRC32() computes the 32-bit CRC for a buffer.
- extern UInt32 CRC32(UInt8 *, Size);
-
- /******************************************************************************/
-
- #endif // __ENETWARTS_H__
-
- typedef struct Enet Enet;
- typedef Enet * EnetPtr;
-
- typedef struct EnetMAC EnetMAC;
- typedef EnetMAC * EnetMACPtr;
-
- typedef struct EnetAddressListElement EnetAddressListElement;
- typedef EnetAddressListElement * EnetAddressListPtr;
- struct EnetAddressListElement
- {
- EnetAddressListPtr next;
- EnetAddress address;
- UInt8 _pad[2];
- };
-
- enum EnetMode
- {
- kEnetHalted = 0,
- kEnetSynchronousILB = 1,
- kEnetAsynchronousILB = 2,
- kEnetSynchronousNLB = 3,
- kEnetAsynchronousNLB = 4
- };
- typedef UInt32 EnetMode;
-
- enum TxBufferState
- {
- kTxPacketComplete = 0,
- kTxPacketDropped = 1,
- kTxBufferBusy = 2
- };
- typedef UInt32 TxBufferState;
-
- enum
- {
- TX_CRC_ERROR = DL_CRC_ERROR,
- TX_RUNT_ERROR = DL_RUNT_ERROR,
- TX_FRAMING_ERROR = DL_FRAMING_ERROR
- };
- typedef UInt32 TxErrorFlags;
-
- typedef struct TxBuffer TxBuffer;
- typedef TxBuffer * TxBufferPtr;
- typedef TxBuffer TxPacket;
- typedef TxPacket * TxPacketPtr;
-
- struct TxBuffer
- {
- TxBufferPtr recycleNext;
- TxBufferPtr * recycleList;
- TxBufferPtr packetNext;
- EnetPtr enet;
- UInt8 * data;
- UInt32 phyAddress;
- UInt32 phyAddressES;
- Count allocated;
- Count used;
- Count packetSize;
- Count bufferCount;
- Count retryCount;
- TxBufferState state;
- TxErrorFlags flags;
- };
-
- enum {
- RX_NO_ERROR = DL_NO_ERROR,
- RX_MAC_ERROR = DL_MAC_ERROR,
- RX_BAD_802_3_LENGTH = DL_BAD_802_3_LENGTH,
- RX_FRAMING_ERROR = DL_FRAMING_ERROR,
- RX_RUNT_ERROR = DL_RUNT_ERROR,
- RX_CRC_ERROR = DL_CRC_ERROR,
- RX_ERROR_MASK = RX_CRC_ERROR | \
- RX_RUNT_ERROR | \
- RX_FRAMING_ERROR | \
- RX_BAD_802_3_LENGTH | \
- RX_MAC_ERROR,
- RX_RECONNECT = 0x00000100
- };
- typedef UInt32 RxErrorFlags;
-
- typedef struct RxBuffer RxBuffer;
- typedef RxBuffer * RxBufferPtr;
- typedef RxBuffer RxPacket;
- typedef RxPacket * RxPacketPtr;
-
- struct RxBuffer {
- RxBufferPtr recycleNext;
- RxBufferPtr * recycleList;
- RxBufferPtr packetNext;
- EnetPtr enet;
- UInt8 * data;
- UInt32 phyAddress;
- UInt32 phyAddressES;
- Count allocated;
- Count used;
- Count packetSize;
- Count bufferCount;
- RxErrorFlags flags;
- Count busy;
- UInt32 misc[4];
- };
-
- // EnetModeName() returns an EnetMode name string.
- extern char *EnetModeName(EnetMode);
-
- // EnetAddressCRC() calculates the 32-bit CRC for an ethernet address.
- extern UInt32 EnetAddressCRC(EnetAddressPtr);
-
- // EnetCheckTxBuffer() checks that a transmit buffer has not been stepped on.
- // Returns false if there was an error.
- extern Boolean EnetCheckTxBuffer(EnetPtr, TxBufferPtr);
-
- // EnetCheckTxPacket() checks that a transmit packet has not been stepped on.
- // Returns false if there was an error.
- extern Boolean EnetCheckTxPacket(EnetPtr, TxPacketPtr);
-
- // EnetTxCheck() checks the transmit buffer pool.
- // Returns false if there is an error.
- extern Boolean EnetTxCheck(EnetPtr);
-
- // EnetReturnTxBuffer() returns a buffer to the transmit buffer pool.
- extern void EnetReturnTxBuffer(TxBufferPtr);
-
- // EnetGetTxBuffer() gets a buffer from the transmit buffer pool.
- // Returns NULL if blocked.
- extern TxBufferPtr EnetGetTxBuffer(EnetPtr);
-
- // EnetReturnTxPacket() returns a packet to the transmit buffer pool.
- // A packet is a list of buffers...
- extern void EnetReturnTxPacket(TxPacketPtr);
-
- // EnetGetTxPacket() converts packet data to a transmit buffer.
- // The data pointer can be NULL.
- // Returns a pointer to the TxBuffer list.
- // Returns NULL if there was an error.
- extern TxPacketPtr EnetGetTxPacket(EnetPtr, void *, Size);
-
- // EnetTxUnblock() prepares to unblock the transmitter.
- // TxUnblock() is called when enough packets have been sent.
- typedef void (*EnetTxUnblockPtr)(void *);
- extern void EnetTxUnblock(EnetPtr, EnetTxUnblockPtr, void *cookie);
-
- // EnetTxService() recycles TxBuffers from the TxRing.
- // Wait for a packet to transmit/timeout if specified.
- extern void EnetTxService(EnetPtr, TxPacketPtr wait);
-
- // EnetTxPacket() attempts to transmit a normal packet.
- // Returns NULL if the packet is accepted to be transmitted or dropped.
- // Returns the packet pointer if blocked.
- extern TxPacketPtr EnetTxPacket(EnetPtr, TxPacketPtr);
-
- // EnetTxBadPacket() attempts to transmit a bad packet.
- // Returns NULL if the packet is accepted to be transmitted or dropped.
- // Returns the packet pointer if blocked.
- extern TxPacketPtr EnetTxBadPacket(EnetPtr, TxPacketPtr, TxErrorFlags);
-
- // EnetCheckRxBuffer() checks that a receive buffer has not been stepped on.
- // Returns false if there was an error.
- extern Boolean EnetCheckRxBuffer(EnetPtr, RxBufferPtr);
-
- // EnetCheckRxPacket() checks that a receive packet has not been stepped on.
- // Returns false if there was an error.
- extern Boolean EnetCheckRxPacket(EnetPtr, RxPacketPtr);
-
- // EnetRxCheck() checks the receive buffer pool.
- // Returns false if there is an error.
- extern Boolean EnetRxCheck(EnetPtr);
-
- // EnetReturnRxBuffer() returns an buffer to the receive buffer pool.
- extern void EnetReturnRxBuffer(RxBufferPtr);
-
- // EnetGetRxBuffer() gets a buffer from the receive buffer pool.
- // Returns NULL if blocked.
- extern RxBufferPtr EnetGetRxBuffer(EnetPtr);
-
- // EnetReturnRxPacket() returns a packet to the receive buffer pool.
- // A packet is a list of buffers...
- extern void EnetReturnRxPacket(RxPacketPtr);
-
- // EnetRxPacket() tries to receive a packet.
- // Returns NULL if blocked.
- extern RxPacketPtr EnetRxPacket(EnetPtr);
-
- // EnetStop() halts the transmit and receive processes.
- // Returns false if there was an error.
- extern Boolean EnetStop(EnetPtr);
-
- // EnetStart() starts the transmit and receive processes.
- // Returns false if there was an error.
- // The Modes are:
- // kEnetSynchronousILB SYNCHRONOUS / LOOPBACK.
- // kEnetAsynchronousILB ASYNCHRONOUS / LOOPBACK.
- // kEnetSynchronousNLB SYNCHRONOUS / NO LOOPBACK.
- // kEnetAsynchronousNLB ASYNCHRONOUS / NO LOOPBACK.
- // The timeout is for SYNCHRONOUS receive and transmit.
- // The txMaxBuffer is the number of buffers in the transmit pool.
- // The txMaxService is the maximum number of buffers that trigger service.
- // The txMinUnblock is the maximum number of buffers sent before unblocking.
- // The rxMaxBuffer is the number of buffers in the receive pool.
- // The rxMinService1 is minimum number of buffers that trigger service.
- // The rxMinService2 is minimum number of buffers that trigger service.
- // The addressList contains both unicast and multicast addresses.
- // The acceptErrors enables error packets to be received.
- // The RxISR() is applied to the rxCookie for ASYNCHRONOUS packets.
- typedef void (*EnetRxISRPtr)(void *);
- extern Boolean
- EnetStart(EnetPtr enet,
- EnetMode mode,
- Count timeout,
- Count txMaxBuffer,
- Count txMaxService,
- Count txMinUnblock,
- Count rxMaxBuffer,
- Count rxMinService1,
- Count rxMinService2,
- EnetAddressListPtr addressList,
- Boolean acceptErrors,
- EnetRxISRPtr RxISR,
- void *rxCookie);
-
- // EnetDiagnostic() performs diagnostic tests.
- // Returns false if there was an error.
- extern Boolean EnetDiagnosticTest(EnetPtr);
-
- // EnetStatus() composes a status report.
- // Call with a NULL BPrintfBuffer pointer to clear the status.
- extern void EnetStatus(EnetPtr, BPrintfBufferPtr);
-
- // EnetClose() terminates access to the Enet and MAC modules.
- // It invalidates the EnetPtr and returns NULL.
- // Returns the EnetPtr if there was an error.
- // WARNING: If there was an error, then the driver is *NOT* closed!
- // This will happen if any buffers were not returned to the pool.
- extern EnetPtr EnetClose(EnetPtr);
-
- // EnetOpen() prepares the Enet module for operation.
- // Full kernel services must be available.
- // The MAC module will be opened.
- // Returns a pointer to the allocated Enet structure.
- // Returns NULL if there was an error.
- extern EnetPtr
- EnetOpen(void *enetCookie,
- char *driverName,
- dle_interface_status_t *iStatus,
- dle_ethernet_status_t *eStatus,
- MPrintfPtr m,
- char **chipName,
- EnetAddressListPtr *addressList);
-
- // EnetProbe() tests for the existance of Enet hardware.
- // Returns false if there is no hardware.
- extern Boolean EnetProbe(void *enetCookie, char *driverName);
-
- // RetrieveSoftEthernetAddress() retrieves the user-specified Ethernet address,
- // if one exists in an 'eadr' resource, or in the Name Registry.
- extern int RetrieveSoftEthernetAddress(RegEntryID *theID, EnetAddress eAddress);
-
- /******************************************************************************/
-
- // MacStatus() composes a status report for EnetStatus().
- // Call with a NULL BPrintfBuffer pointer to clear the status.
- typedef void (*MacStatusPtr)(EnetMACPtr, BPrintfPtr);
-
- // MacTxUnblock() prepares to unblock the transmitter.
- // TxUnblock() is called when enough packets have been sent.
- typedef void
- (*MacTxUnblockPtr)(EnetMACPtr, EnetTxUnblockPtr TxUnblock, void *);
-
- // MacTxService() recycles TxBuffers from the TxRing.
- typedef void (*MacTxServicePtr)(EnetMACPtr, TxPacketPtr);
-
- // MacTxCheck() checks that the transmitter is not broken.
- // Returns false if there was an error.
- typedef Boolean (*MacTxCheckPtr)(EnetMACPtr);
-
- // MacTxReset() prepares the transmit ring.
- // Returns false if there was an error.
- typedef Boolean (*MacTxResetPtr)(EnetMACPtr, Count maxBuffer);
-
- // MacTxPacket() transmits normal packets.
- // Returns NULL if the packet will be transmitted or dropped.
- // Returns the packet pointer if blocked.
- typedef TxPacketPtr (*MacTxPacketPtr)(EnetMACPtr, TxPacketPtr);
-
- // MacTxBadPacket() transmits error packets.
- // Returns NULL if the packet will be transmitted or dropped.
- // Returns the packet pointer if blocked.
- typedef TxPacketPtr (*MacTxBadPacketPtr)(EnetMACPtr, TxPacketPtr, TxErrorFlags);
-
- // MacRxCheck() checks that the receiver is not broken.
- // Returns false if there was an error.
- typedef Boolean (*MacRxCheckPtr)(EnetMACPtr);
-
- // MacRxReset() prepares the receive ring.
- // Returns false if there was an error.
- typedef Boolean (*MacRxResetPtr)(EnetMACPtr, Count maxBuffer);
-
- // MacRxService() fills the RxRing with RxBuffers.
- typedef void (*MacRxServicePtr)(EnetMACPtr mac);
-
- // MacRxPacket() receives a packet.
- // Returns NULL if blocked.
- typedef RxPacketPtr (*MacRxPacketPtr)(EnetMACPtr);
-
- // MacStop() stops the transmit and receive processes.
- // Returns false if there was an error.
- typedef Boolean (*MacStopPtr)(EnetMACPtr);
-
- // MacStart() starts the transmit and receive processes.
- // Returns false if there was an error.
- typedef Boolean
- (*MacStartPtr)(EnetMACPtr,
- EnetMode,
- Count timeout,
- Count txMinUnblock,
- Count txMaxService,
- Count rxMinService1,
- Count rxMinService2,
- UInt32 *connectedSpeed,
- EnetAddressListPtr,
- Boolean acceptErrors,
- EnetRxISRPtr RxISR,
- void *rxCookie);
-
- // MacClose() terminates access to the MAC module.
- // The EnetMACPtr is invalidated.
- // Returns NULL.
- typedef EnetMACPtr (*MacClosePtr)(EnetMACPtr);
-
- //
- // An EnetMACPtr is the first element of a Enet structure.
- //
- struct EnetMAC
- {
- MacStatusPtr MacStatus;
- MacTxUnblockPtr MacTxUnblock;
- MacTxServicePtr MacTxService;
- MacTxCheckPtr MacTxCheck;
- MacTxResetPtr MacTxReset;
- MacTxPacketPtr MacTxPacket;
- MacTxBadPacketPtr MacTxBadPacket;
- MacRxCheckPtr MacRxCheck;
- MacRxResetPtr MacRxReset;
- MacRxServicePtr MacRxService;
- MacRxPacketPtr MacRxPacket;
- MacStopPtr MacStop;
- MacStartPtr MacStart;
- MacClosePtr MacClose;
- };
-
- // MacOpen() prepares the MAC module for operation.
- // Returns a pointer to the allocated EnetMAC structure.
- // Returns NULL if there was an error.
- extern EnetMACPtr
- MacOpen(void *enetCookie,
- char *driverName,
- EnetPtr,
- dle_ethernet_status_t *,
- MPrintfPtr,
- UInt32 *minTxBufferSize,
- UInt32 *minRxBufferSize,
- UInt32 *maxPacketSize,
- char **chipName,
- EnetAddressListPtr *addressList);
-
- /******************************************************************************/
-
- #endif // __ENETLIB_H__
-